import { api } from './api.js'

export default {
	fetchPost (url, params = {}) {
    return new Promise((resolve, reject) => {
			var token = uni.getStorageSync('token');
      uni.request({
      	url: `${api}`+url, //仅为示例，并非真实接口地址。
      	method:'post',
				data: params,
				header:{
					'Content-Type': 'application/x-www-form-urlencoded',
					'token': token
				},
      	success: (res) => {
					if(res.data.errorNo == 0){
						resolve(res.data)
					}else {
						//未绑定手机号
						if(res.data.errorNo == '-901'){
							uni.reLaunch({
								url: '/pages/login/binding/binding'
							});
							return false;
						}
						//未绑定推荐人
						if(res.data.errorNo == '-902'){
							uni.reLaunch({
								url: '/pages/login/relation/relation'
							});
							return false;
						}
						//登录过期
						if(res.data.errorNo == '-999'){
							uni.reLaunch({
								url: '/pages/login/login/login'
							});
							return false;
						}
						uni.showToast({
								title: res.data.errorInfo,
								icon: 'none',
								duration: 2000
						});
						reject(res.data);
					}
      	}
      });
    })
  },
}